﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Xpom_Xpum__Integrated_Development_Environment.Model;
using Xpom_Xpum__Integrated_Development_Environment.Model.Controls;

namespace Xpom_Xpum__Integrated_Development_Environment.View
{
    /// <summary>
    /// Interaction logic for NewItemWindowView.xaml
    /// </summary>
    public partial class NewItemWindowView : Window
    {
        #region Constructor

        public NewItemWindowView()
        {
            InitializeComponent();
            this.DataContext = ((App)Application.Current).niwvm;
        }

        #endregion

        #region Commands

        #endregion

        #region Fields

        #endregion

        #region Properties

        #endregion

        #region Methods

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
            this.Visibility = Visibility.Hidden;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            ProjectItemModel parent;

            var selectedItem = ((App)App.Current).pevm.SelectedItem;

            if (selectedItem != null)
            {
                if (selectedItem.IsDirectory)
                {
                    parent = ((App)App.Current).pevm.SelectedItem;
                }
                else
                {
                    parent = ((App)App.Current).pevm.Items[0];
                }
            }
            else
            {
                parent = ((App)App.Current).pevm.Items[0];
            }

            //

            ItemTemplate selectedTemplate = listView1.SelectedItem as ItemTemplate;

            var newItemPath = parent.Path + "\\" + textBox1.Text;

            if (selectedTemplate.ItemTemplateNameEN == "Folder")
            {
                System.IO.Directory.CreateDirectory(newItemPath);
            }
            else
            {
                System.IO.File.Create(newItemPath).Close();
            }

            //

            ((App)App.Current).pevm = new ViewModel.Controls.ProjectExplorerViewModel(((App)App.Current).pevm.ProjectDirectory);

            this.Close();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        #endregion
    }
}
